package com.bluesky.service.lesson012;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bluesky.comm.ServiceExceptionUtils;
import com.bluesky.mapper.lesson012.AccountMapper;
import com.bluesky.po.lesson012.AccountPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountPO>  implements AccountService{

    @Autowired
    private AccountMapper accountMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void balanceAdd(String accountId, BigDecimal price) {
        int updateCount = accountMapper.balanceAdd(accountId,price);
        if (updateCount != 1){
            throw ServiceExceptionUtils.exception("更新账户余额失败！");
        }
    }
}
